﻿using System;
using RAP.Framework.Libary.Utils;
using System.ComponentModel;
using RAP.Framework.Libary.DomTemplateBuilder.Attributes;
using RAP.Framework.Libary.DomTemplateBuilder.Handler;

namespace RAP.Framework.Libary.DomTemplateBuilder.Element.Collection
{
	/// <summary>
	/// 循环节点
	/// </summary>
	[Description( "循环节点" )]
    [TagHandler( typeof( IterateHandler ) )]
    public class Iterate : PropertyElement
    {
        public string Conjunction
        {
            get
            {
                return this.ToString( "Conjunction" );
            }
        }

        public string Open
        {
            get
            {
                return this.ToString( "Open" );
            }
        }

        public string Close
        {
            get
            {
                return this.ToString( "Close" );
            }
        }

        public bool IgnoreEmpty
        {
            get
            {
                return this.ToBoolean( "IgnoreEmpty" );
            }
        }

        public int StartIndex
        {
            get
            {
                return this.ToInt32( "StartIndex", 0 );
            }
        }

        public int Length
        {
            get
            {
                return this.ToInt32( "Length", -1 );
            }
        }

        public string ItemAlias
        {
            get
            {
                return this.ToString( "ItemAlias" );
            }
        }

        protected TypeCode? _itemValueType = null;
        /// <summary>
        /// 值类型
        /// </summary>
        public virtual TypeCode ItemValueType
        {
            get
            {
                if ( this._itemValueType == null )
                {
                    lock ( this )
                    {
                        if ( this._itemValueType == null )
                        {
                            _itemValueType = this.ToEnumValue<TypeCode>( "ItemValueType", TypeCode.Empty );
                        }
                    }
                }
                return _itemValueType.Value;
            }
        }

        /// <summary>
        /// 是否去除循环输出中的重复值
        /// </summary>
        public bool DistinctValue
        {
            get
            {
                return this.ToBoolean( "DistinctValue" );
            }
        }
    }
}
